package com.yzcrm.erp.kms.controller.mobile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.paragetter.Para;
import com.yzcrm.common.annotation.NotNullValidate;
import com.yzcrm.common.annotation.Permissions;
import com.yzcrm.common.config.paragetter.BasePageRequest;
import com.yzcrm.erp.admin.service.AdminFieldService;
import com.yzcrm.erp.crm.common.CrmEnum;
import com.yzcrm.erp.kms.service.KmsBbsService;
import com.yzcrm.swagger.annotation.ActionApi;
import com.yzcrm.swagger.annotation.Api;
import com.yzcrm.swagger.annotation.Param;
import com.yzcrm.swagger.annotation.Params;
import com.yzcrm.utils.R;

/**
 * @author jiang.xue
 * 论坛帖子
 */
@Api(remark = "知识库：论坛帖子")
public class KmsMobileBBSController extends Controller{

    @Inject
    private AdminFieldService adminFieldService;

    @Inject
    private KmsBbsService kmsBbsService;

    /**
     * 查看列表页
     */
//    @Permissions({"kms:bbs:index"})
    @ActionApi(summary = "论坛帖子列表数据", remark="论坛帖子列表数据")
    @Params({
            @Param(name="sceneId", remark="场景Id", dataType="int", defaultValue="", required=false),
            @Param(name="type", remark="权限标识 103：帖子（bbs）", dataType="int", defaultValue="", required=true)
    })
    public void queryPageList(BasePageRequest basePageRequest) {

        JSONObject jsonObject = basePageRequest.getJsonObject().fluentPut("type", CrmEnum.KMS_BBS.getType());
        basePageRequest.setJsonObject(jsonObject);
        renderJson(kmsBbsService.filterConditionAndGetPageList(basePageRequest));
    }

    /**
     * 添加或者修改论坛帖子
     */
    @ActionApi(summary = "添加或者修改论坛帖子", remark="添加或者修改论坛帖子")
//    @Permissions({"kms:bbs:save", "kms:bbs:update"})
    public void saveOrUpdate(){

        JSONObject jsonObject = JSON.parseObject(getRawData());
        renderJson(kmsBbsService.addOrUpdate(jsonObject));
    }

    /**
     * 根据id删除论坛帖子
     */
    @ActionApi(summary = "根据id删除论坛帖子", remark="根据id删除论坛帖子")
    @Params({
            @Param(name="bbsId", remark="论坛帖子ID", dataType="String", defaultValue="", required=true)
    })
//    @Permissions("kms:bbs:delete")
    @NotNullValidate(value = "bbsId", message = "论坛帖子id不能为空")
    public void deleteByIds(@Para("bbsId") String bbsId) {
        renderJson(kmsBbsService.deleteByIds(bbsId));
    }

    /**
     * 根据论坛帖子id查询
     */
    @ActionApi(summary = "根据id查询论坛帖子", remark="根据id查询论坛帖子")
    @Params({
            @Param(name="bbsId", remark="论坛帖子ID", dataType="String", defaultValue="", required=true)
    })
//    @Permissions("kms:bbs:read")
    @NotNullValidate(value = "bbsId", message = "论坛帖子id不能为空")
    public void queryById(@Para("bbsId") Integer bbsId) {
        renderJson(R.ok().put("data", kmsBbsService.queryById(bbsId)));
    }


}
